package ru.amse.tsyganov.jumleditor.commands;

import ru.amse.tsyganov.jumleditor.view.lines.Line;

/*package*/ class MoveHorizontalLineCommand extends Command {
	
	private final Line line;
	
	private final int oldY1;
	
	private final int oldY2;
	
	private final int newY1;
	
	private final int newY2;

	public MoveHorizontalLineCommand(
			Line line, 
			int newY1, 
			int newY2) {
		
		if (line == null) {
			throw new IllegalArgumentException();
		}
		
		this.line = line;
		oldY1 = line.getY1();
		oldY2 = line.getY2();
		this.newY1 = newY1;
		this.newY2 = newY2;
		
		if (oldY2 == newY2 && oldY1 == newY1) {
			throw new IllegalArgumentException();
		}
	}
	
	@Override
	public void execute() {
		line.setY1(newY1);
		line.setY2(newY2);
	}

	@Override
	public void unexecute() {
		line.setY1(oldY1);
		line.setY2(oldY2);
	}

}
